package com.itheima.test4;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class ServiceDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(33333);

        Lo:
        while (true) {
            Socket socket = null;
            socket = ss.accept();
            InputStream is = socket.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String len;
            OutputStream os = socket.getOutputStream();
            OutputStreamWriter osw = new OutputStreamWriter(os);
            BufferedWriter bw = new BufferedWriter(osw);
            while ((len = br.readLine()) != null) {
                if ("exit".equalsIgnoreCase(len)) {
//                    bw.write("exit");
//                    bw.flush();
                    System.exit(0);
                    break Lo;
                }
                System.out.println(len);
            }
            Scanner sc = new Scanner(System.in);
            String data = sc.next();
            bw.write(data);
            bw.flush();
            socket.close();
        }
        ss.close();
    }
}
